package edu.ucsb.cs56.W12.chatserver.controller;

import edu.ucsb.cs56.W12.chatserver.model.Server;
import edu.ucsb.cs56.W12.chatserver.view.ServerWindow;

/**
 * ServerController Class represent the controller which handles
 * the communication between view and model
 * @author Peng Wang and Andro Stotts
 * @version 0.1
 */
public class ServerController{
	private Server server;
	private static ServerController controller;
	
	/**
	 * Constructor that gets a instance of Server class
	 */
	private ServerController(){
		server = Server.getServer();
	}
	
	/**
	 * get the instance of ServerController class
	 * @return instance of ServerController
	 */
	public static ServerController getController(){
		if(controller == null)
			controller = new ServerController();
		return controller;
	}
	
	/**
	 * tell the server object to start the server
	 * @return server message
	 */
	public String startServer(){	
		server.start();
		return server.getServerMsg();	
	}
	
	/**
	 * tell the server object to close server
	 * @return server message
	 */
	public String closeServer(){
		server.close();
		return server.getServerMsg();
	}
	
	/**
	 * get the server status
	 * @return true when server is running, otherwise false
	 */
	public boolean getServerStatus(){
		return server.getServerStatus();
	}
	
	/**
	 * display the message on the server GUI
	 * @param s message to display
	 */
	public void displayMsg(String s){
		ServerWindow.getWindow().getTaConsole().append(s);
	}
}
